/***************************************************************************
 *   Copyright (C) 2014 by Philipp Müller                                  *
 *   philipp.mueller@gmx.de                                                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA          *
 ***************************************************************************/

import QtQuick 2.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Controls 1.2

Rectangle {
    id: container

    property string inputText: textInput.text
    signal closed

    color: "black"
    border.color: "white"
    border.width: 2

    function show( text ) {
        dialogText.text = text;

        container.opacity = 1;
        textInput.opacity = 1;

        textInput.focus = true;
        textInput.text = ""
    }

    function hide() {
        textInput.focus = false;
        container.opacity = 0;
        container.closed();
    }

    width: 50 * screenScale + dialogText.width
    height: dialogText.height + textInput.height + buttonCancel.height + 50 * screenScale
    opacity: 0
    visible: opacity > 0

    Column{
        spacing: 20 * screenScale
        anchors { verticalCenter: parent.verticalCenter;
                  horizontalCenter: parent.horizontalCenter;
                  left: parent.left;
                  leftMargin: 10 * screenScale }
        Text {
            id: dialogText
            color: "white"
            text: ""
            font.pixelSize: 18 * screenScale
        }

        TextField {
            id: textInput
            width: 160 * screenScale
            text: ""
            style: touchStyle
            font.pixelSize: 18 * screenScale

            onAccepted: {
                console.log( "Dialog accepted inputText: " + textInput.text )
                container.hide() // close dialog when Enter is pressed
            }
        }

        ButtonMenu {
            id: buttonCancel
            anchors.horizontalCenter: parent.horizontalCenter
            text: qsTr( "Ok" )
            icon: ""
            onClicked: {
                hide();
                console.log( "IP enter ok" )
            }
        }
    }
}
